package com.tater.springboot.controller;

import com.github.pagehelper.PageInfo;
import com.tater.springboot.model.Article;
import com.tater.springboot.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {


    @Autowired
    ArticleService articleService;

    @GetMapping("/index")
    public String index(@RequestParam(required = false,defaultValue = "1")Integer page, Model model){
        PageInfo pageInfo = articleService.articleList(page);
//        List<Article> articles = new ArrayList<>();
        model.addAttribute("articles",pageInfo.getList());
        model.addAttribute("pager",pageInfo);
        model.addAttribute("pageNo",pageInfo.getPageNum());
        return "client/index";
    }
}
